// miniprogram/pages/wen1/wen1.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page_index: "zwcx",
    show_tab_bar: !0,
    yearList: ['2018', '2019', '2020', '2021', '2022'],
    eduList: ['大专', '本科', '研究生'],
    zzmmList: ['不限', '中共党员', '共青团员'],
    gzjlList: ['二年', '无限制'],
    cengjiList: ['中央', '省（副省）级', '市（地）级', '县（区）级及以下'],
    self: 1
  },
  self() {
    var that = this;
    that.setData({
      self: 1
    })
  },
  noself() {
    var that = this;
    that.setData({
      self: !1
    })
  },
  //个人信息查询提交
  submit() {
    var that = this;
    var phone = wx.getStorageSync('phone')
    var edu = that.data.edu;
  
    if (phone) {
      if (that.data.city && that.data.edu && that.data.zhuanyemingcheng && that.data.zzmm && that.data.gzjl) {
        wx.request({ //发送请求
          url: 'https://zg99.offcn.com/index/chaxun/getlist?actid=42754&callback=?', //接收url
          data: {
            limits: 500,
            year: that.data.year,
            gzdd: that.data.city,
            xlpp: that.data.edu,
            zhuanye: that.data.zhuanyemingcheng,
            zzmm: that.data.zzmm,
            gzjl: that.data.gzjl,
          }, //接收参数
          success(res) { //返回
            var jsonStr = res.data;
            jsonStr = jsonStr.replace("(", "");
            jsonStr = jsonStr.replace(")", "");
            if (typeof jsonStr != 'object') {
              jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
              var theJson = JSON.parse(jsonStr);
            }
            console.log(theJson)
            var list1 = [];
            for (var i in theJson.lists) { //循环写入下来框
              list1.push(theJson.lists[i])
            }
            wx.request({ //发送请求
              url: 'https://zg99.offcn.com/index/chaxun/getlist?actid=42754&callback=?', //接收url
              data: {
                limits: 500,
                year: that.data.year,
                gzdd: that.data.city,
                xueli: that.data.edu,
                zhuanye: that.data.zhuanyeleibie,
                zzmm: that.data.zzmm,
                gzjl: that.data.gzjl,
              }, //接收参数
              success(res) {
                console.log('2') //返回
                var jsonStr = res.data;
                jsonStr = jsonStr.replace("(", "");
                jsonStr = jsonStr.replace(")", "");
                if (typeof jsonStr != 'object') {
                  jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                  var theJson = JSON.parse(jsonStr);
                }
                 console.log(theJson)
                var list2 = [];
                for (var i in theJson.lists) { //循环写入下来框
                  list2.push(theJson.lists[i])
                }
                var list = list1.concat(list2)
                that.setData({
                  selfres: list
                });
                if (list.length != 0) {
                  wx.setStorageSync('theJson', list)
                  wx.navigateTo({
                    url: "/pages/result/result"
                  });
                  console.log(list)
                } else {
                  wx.showToast({
                    title: '无符合条件岗位',
                  })
                }

              }
            })
          }
        })
      } else {
        wx.showToast({
          title: '请完整填写信息',
          duration: 2000,
          icon: 'none'
        })
      }

    } else {
      wx.showToast({
        title: '请先登录',
        duration: 2000,
        icon: 'none'
      })
      that.setData({
        login: 1
      })
    }
  },
  //职位信息查询提交
  submitother() {
    var that = this;
    var phone = wx.getStorageSync('phone')
    if (phone) {
      if (that.data.city && that.data.cengji && that.data.jgmc && that.data.zlzw) {
        wx.request({ //发送请求
          url: 'https://zg99.offcn.com/index/chaxun/getlist?actid=42754&callback=?', //接收url
          data: {
            limits: 500,
            year: that.data.year,
            gzdd: that.data.city,
            jgcj: that.data.cengji,
            jgmc: that.data.jgmc,
            zlzw: that.data.zlzw,
          }, //接收参数
          success(res) { //返回
            var jsonStr = res.data;
            jsonStr = jsonStr.replace("(", "");
            jsonStr = jsonStr.replace(")", "");
            if (typeof jsonStr != 'object') {
              jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
              var theJson = JSON.parse(jsonStr);
            }
            console.log(theJson)
            that.setData({
              noselfres: theJson.lists
            });


            if (theJson.status != 2) {
              wx.setStorageSync('theJson', theJson.lists)
              wx.navigateTo({
                url: "/pages/result/result"
              });
            } else {
              wx.showToast({
                title: '该年度无此岗位，请更换年份',
                icon: 'none'
              })
            }
          }
        })
      } else {
        wx.showToast({
          title: '请完整填写信息',
          duration: 2000,
          icon: 'none'
        })
      }
    } else {
      wx.showToast({
        title: '请先登录',
        duration: 2000,
        icon: 'none'
      })
      that.setData({
        login: 1
      })
    }

  },
  getPhoneNumber(e) {
    var _ = this;
    wx.cloud.callFunction({
      name: 'getMobile',
      data: {
        weRunData: wx.cloud.CloudID(e.detail.cloudID),
      }
    }).then(res => {
      _.setData({
        mobile: res.result,
      })
      console.log(res.result)
      var area = wx.getStorageSync('area')
      var agent = wx.getStorageSync('agent')
      var page = wx.getStorageSync('page')
      wx.request({
        url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/collect_v3',
        method: 'POST',
        data: {
          activeId: 9,
          mobile: res.result,
          areaCode: area,
          agent: agent,
          pageId: page
        },
        success: res => {
          console.log(res);
        }
      })

      wx.setStorageSync('phone', _.data.mobile)
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/chaxun/register?actid=42754&callback=?', //接收url
        data: {
          phone: _.data.mobile,
          fenxiao: area,
          geneal: agent,
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson)
          _.setData({
            login: !1
          })
        }
      });

    })

  },
  gozx: function () {
    wx.navigateTo({
      url: '../../xiaoneng/xiaoneng',
    })
  },
  //点击选择-年份year
  choiseyear() {
    var that = this;
    that.setData({
      bindyear: 1,
    })
  },
  //点击选择-年份year
  setyear(e) {
    var that = this;
    console.log(e.currentTarget.dataset.year)
    that.setData({
      year: e.currentTarget.dataset.year,
      bindyear: !1
    })
  },
  //点击选择-机构层级cengji
  choisecengji() {
    var that = this;
    that.setData({
      bindcengji: 1,
    })
  },
  
  //点击选择-机构层级cengji
  setcengji(e) {
    var that = this;
    console.log(e.currentTarget.dataset.cengji)
    that.setData({
      cengji: e.currentTarget.dataset.cengji,
      bindcengji: !1
    })
  },
  //点击选择-部门名称jgmc
  choisejgmc() {
    var that = this;
    that.setData({
      bindjgmc: 1,
    });
    that.jgmc()
  },
  //2级联动-部门名称jgmc
  jgmc() {
    var that = this;
    console.log(that.data.cengji)
    console.log(that.data.city)

    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlist?actid=42754&callback=?', //接收url
      data: {
        limits: 500,
        year: that.data.year,
        gzdd: that.data.city,
        jgcj: that.data.cengji
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson.lists)
        if (theJson.status == 2) {
          list.push('暂无选项，请修改上级条件')
        } else {
          var a =  theJson.lists.length
          console.log(a)
          var arr =[]
          for(var i = 0;i < theJson.lists.length;i++){
            arr.push(theJson.lists[i].jgmc)
          }
          var list = Array.from(new Set(arr))
          console.log(list)
        }
        that.setData({
          jgmcList: list
        });
      }
    })
   
   
  },
  //点击选择-部门名称jgmc
  setjgmc(e) {
    var that = this;
    console.log(e.currentTarget.dataset.jgmc)
    that.setData({
      jgmc: e.currentTarget.dataset.jgmc,
      bindjgmc: !1
    })
  },
  //点击选择-招录职位zlzw
  choisezlzw() {
    var that = this;
    that.setData({
      bindzlzw: 1,
    });
    that.zlzw()
  },
  //4级联动-招录职位zlzw
  zlzw() {
    var that = this;

    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlist?actid=42754&callback=?', //接收url
      data: {
        limits: 500,
        year: that.data.year,
        gzdd: that.data.city,
        jgcj: that.data.cengji,
        jgmc: that.data.jgmc
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson.lists)
        if (theJson.status == 2) {
          list.push('暂无选项，请修改上级条件')
        } else {
          var a =  theJson.lists.length
          console.log(a)
          var arr =[]
          for(var i = 0;i < theJson.lists.length;i++){
            arr.push(theJson.lists[i].zlzw)
          }
          var list = Array.from(new Set(arr))
          console.log(list)
        }
        that.setData({
          zlzwList: list
        });
      }
    })
    
  },
  //点击选择-招录职位zlzw
  setzlzw(e) {
    var that = this;
    console.log(e.currentTarget.dataset.zlzw)
    that.setData({
      zlzw: e.currentTarget.dataset.zlzw,
      bindzlzw: !1
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log(options);
    wx.setStorageSync('area', options.area)
    wx.setStorageSync('agent', options.agent)
    wx.setStorageSync('page', options.page)
    that.province();
  },
  closeselect() {
    var that = this;
    that.setData({
      bindpro: !1,
      bindmajor: !1,
      bindedu: !1,
      bindgzjl: !1,
      bindzzmm: !1,
      bindcengji: !1,
      bindjgmc: !1,
      bindzlzw: !1,
      bindyear: !1,
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  //点击选择-学历edu
  choiseMajor() {
    var that = this;
    if (that.data.edu) {
      that.setData({
        bindmajor: 1,
      })
      that.xuekemenlei()
    } else {
      wx.showToast({
        title: '请先选择学历',
        icon: 'none'
      })
    }

  },
  //2级联动-学科门类
  xuekemenlei() {
    var that = this;
    var edu 
    if(that.data.edu == '大专'){
       edu = '专科'
    } else {
      edu = that.data.edu
    }
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=36592&callback=?', //接收url
      data: {
        level: '2',
        grfiled: 'xueli',
        grtext: edu
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        // console.log(theJson)
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].xuekemenlei)
        }
        console.log(list)
        that.setData({
          xuekemenleiList: list
        });
      }
    })
  },
  //点击选择-学科门类xuekemenlei
  setxuekemenlei(e) {
    var that = this;
    console.log(e.currentTarget.dataset.xuekemenlei)
    that.setData({
      xuekemenlei: e.currentTarget.dataset.xuekemenlei,
    })
    that.zhuanyeleibie();
  },
  //点击重新选择-学科门类xuekemenlei
  rechoisexuekemenlei() {
    var that = this;
    that.setData({
      zhuanyeleibieList: !1,
      zhuanyemingchengList: !1,
      zhuanyeleibie: !1
    })
  },
  //3级联动-专业类别
  zhuanyeleibie() {
    var that = this;
    var edu 
    if(that.data.edu == '大专'){
       edu = '专科'
    } else {
      edu = that.data.edu
    }
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=36592&callback=?', //接收url
      data: {
        level: '3',
        grfiled: 'xuekemenlei',
        grtext: that.data.xuekemenlei,
        onefiled: 'xueli',
        onetext: edu
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].zhuanyeleibie)
        }
        console.log(list)
        that.setData({
          zhuanyeleibieList: list
        });
      }
    })
  },
  //点击选择-专业类别zhuanyeleibie
  setzhuanyeleibie(e) {
    var that = this;
    console.log(e.currentTarget.dataset.zhuanyeleibie)
    that.setData({
      zhuanyeleibie: e.currentTarget.dataset.zhuanyeleibie,

    })
    that.zhuanyemingcheng()
  },
  //点击重新选择-专业类别zhuanyeleibie
  rechoisezhuanyeleibie() {
    var that = this;
    that.setData({
      zhuanyemingchengList: !1,
      zhuanyemingcheng: !1
    })
  },
  //4级联动-专业名称
  zhuanyemingcheng() {
    var that = this;
    var edu 
    if(that.data.edu == '大专'){
       edu = '专科'
    } else {
      edu = that.data.edu
    }
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=36592&callback=?', //接收url
      data: {
        level: '4',
        grfiled: 'zhuanyeleibie',
        grtext: that.data.zhuanyeleibie,
        onefiled: 'xueli',
        onetext: edu,
        twofiled: 'xuekemenlei',
        twotext: that.data.xuekemenlei,
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        var list = [];
        console.log(theJson)
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].zhuanyemingcheng)
        }
        console.log(list)
        that.setData({
          zhuanyemingchengList: list
        });
      }
    })
  },
  //点击选择-专业名称zhuanyemingcheng
  setzhuanyemingcheng(e) {
    var that = this;
    console.log(e.currentTarget.dataset.zhuanyemingcheng)
    that.setData({
      zhuanyemingcheng: e.currentTarget.dataset.zhuanyemingcheng,
      bindmajor: !1
    })
  },
  searchList(event) {
    var that = this;
    var inputVal = (event.detail.value).replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
    console.log(inputVal)
    var edu 
    if(that.data.edu == '大专'){
       edu = '专科'
    } else {
      edu = that.data.edu
    }
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlist?actid=36592&callback=?', //接收url
      data: {
        xueli: edu,
        zhuanyemingcheng: inputVal,
        limits: 500
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        var list = [];
        console.log(theJson)

        that.setData({
          search_res: theJson.lists
        })
        // for (var i in theJson.lists) { //循环写入下来框
        //   list.push(theJson.lists[i].zhuanyemingcheng)
        // }
        // console.log(list)
      }
    })
  },
  bindsearch(e) {
    console.log(e.currentTarget.dataset.set)
    var a = e.currentTarget.dataset.set
    var that = this;
    that.setData({
      xuekemenlei: a.xuekemenlei,
      zhuanyeleibie: a.zhuanyeleibie,
      zhuanyemingcheng: a.zhuanyemingcheng,
      bindmajor: !1,
      search_res: ''
    })
  },
  //点击选择-学历edu
  choiseEdu() {
    var that = this;
    that.setData({
      bindedu: 1,
    })
  },
  //点击选择-学历edu
  setedu(e) {
    var that = this;
    console.log(e.currentTarget.dataset.edu)
    
    that.setData({
      edu: e.currentTarget.dataset.edu,
      bindedu: !1
    })
  },
  //点击选择-政治面貌zzmm
  choiseZzmm() {
    var that = this;
    that.setData({
      bindzzmm: 1,
    })
  },
  //点击选择-政治面貌zzmm
  setzzmm(e) {
    var that = this;
    console.log(e.currentTarget.dataset.zzmm)
    that.setData({
      zzmm: e.currentTarget.dataset.zzmm,
      bindzzmm: !1
    })
  },
  //点击选择-工作年限gzjl
  choisegzjl() {
    var that = this;
    that.setData({
      bindgzjl: 1,
    })
  },
  //点击选择-工作年限gzjl
  setgzjl(e) {
    var that = this;
    console.log(e.currentTarget.dataset.gzjl)
    that.setData({
      gzjl: e.currentTarget.dataset.gzjl,
      bindgzjl: !1
    })
  },
  //点击选择-省份地市
  choiseProvince() {
    var that = this;
    that.setData({
      bindpro: 1,
    })
  },
  //一级联动-省份
  province() {
    var that = this;
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=36591&callback=?', //接收url
      data: {
        level: '1',
        province: ''
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        //console.log(theJson)
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].province)
        }
        // console.log(list)
        that.setData({
          provinceList: list
        });
      }
    })
  },
  //点击选择-省份
  setProvince(e) {
    var that = this;
    console.log(e.currentTarget.dataset.province)
    that.setData({
      province: e.currentTarget.dataset.province
    })
    that.city()
  },
  //点击重新选择-省份
  rechoiseprovince() {
    var that = this;
    that.setData({
      cityList: !1,
      city: !1
    })
  },
  //二级联动-地市
  city() {
    var that = this;
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=36591&callback=?', //接收url
      data: {
        level: '2',
        grfiled: 'province',
        grtext: that.data.province
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        // console.log(theJson)
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].city)
        }
        console.log(list)
        that.setData({
          cityList: list
        });
      }
    })
  },
  //点击选择-地市
  setCity(e) {
    var that = this;
    console.log(e.currentTarget.dataset.city)
    that.setData({
      city: e.currentTarget.dataset.city,
      cityList: !1,
      bindpro: !1
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})